<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>题库管理</title>
    <meta name="description" content="题库管理">
    <meta name="keywords" content="题库管理">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/element-ui.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>

<body class="hold-transition">
<div id="app">
    <div class="content-header common-search-border1">
        <el-button class="butAdd" @click="handleCreate"><i
                class="fa fa-plus" aria-hidden="true"></i> 新增方向
        </el-button>
    </div>
    <div class="app-container">
        <div class="box common-search-border2">
            <div class="filter-container">
                <!-- 搜索栏 -->
                <el-form :inline="true" :model="requestParameters" ref="requestParameters"
                         class="formInfo">
                    <el-form-item label="方向名称" label-width="80px">
                        <el-input placeholder="请输入" v-model="requestParameters.name"
                                  style="width: 200px;" class="filter-item"
                                  @keyup.enter.native="handleFilter"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="状态" label-width="40px">
                         <el-select placeholder="请选择" v-model="requestParameters.isDis">
                             <el-option :key="item.id" :label="item.value" :value="item.id"
                                        v-for="item in baseData.isDis"></el-option>
                         </el-select>
                     </el-form-item>-->
                    <el-form-item>
                        <el-button @click="handleRest">清除</el-button>
                        <el-button type="primary" class="butOK" @click="handleSearch">搜索</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="box common-table-border" style="margin:8px 0 0;">
            <el-table
                    :key="tableKey"
                    :data="items"
                    fit
                    highlight-current-row
                    style="width: 100%;">
                <el-table-column label="序号" width="50px" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.$index+1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="方向名称" align="center">
                    <template slot-scope="scope">
                        <span class="link-type">{{ scope.row.name }}</span>
                    </template>
                </el-table-column>

                <el-table-column label="备注" align="center">
                    <template slot-scope="scope">
                        <span class="link-type">{{ scope.row.remark }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180px">
                    <template slot-scope="scope">
                        <div class="operation">
                            <el-button size="mini" type="danger" @click="handleDeleted(scope.row)"><i
                                    class="fa fa-trash-o" aria-hidden="true"></i> 删除
                            </el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        v-show="pagination.total>0"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.pageNum"
                        :page-sizes="[10, 20, 50, 100]"
                        :page-size="pagination.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
        </div>
        <!-- 新增方向弹层 -->
        <el-dialog title="新增方向" align="center" :visible.sync="dialogFormVisible" width="40%" top="8vh">
            <el-form label-width="120px" :model="form" :rules="rules" ref="form">
                <el-form-item label="方向：" prop="name">
                    <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="备注：" prop="remark">
                    <el-input v-model="form.remark" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="handleCreateCancel">取 消</el-button>
                <el-button type="primary" @click="handleCreateConfirm">确 定</el-button>
            </div>
        </el-dialog>
        <!-- end -->
    </div>

</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/element-ui.js"></script>
<script src="../plugins/jquery/dist/jquery.js"></script>
<script src="../js/data.json"></script>
<script src="../js/base.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                tableKey: 0,
                pagination: {
                    total: 0,
                    pageNum: 1,
                    pageSize: 10
                },
                loading: false,
                items: [],
                baseData: base,
                requestParameters: {
                    name: '',
                    isDis: ''
                },
                dialogFormVisible: false,
                form: {
                    name: '',
                    remark: ''
                },
                rules: {
                    name: [
                        {required: true, message: '请填写', trigger: 'blur'}
                    ]
                }
            }
        },
        created() {
            this.getList()
        },
        methods: {
            getList(pageNo) {
                var t = this;
                if (pageNo) {
                    this.pagination.pageNum = pageNo;
                }
                // 必传参数
                let params = {
                    currentPage: this.pagination.pageNum,
                    pageSize: this.pagination.pageSize,
                    queryParams: {}
                };
                // 选传参数
                let queryParams = {};
                let name = this.requestParameters.name;
                //let isDis = this.requestParameters.isDis;
                if (name !== '') {
                    queryParams.name = name;
                }
                if (Object.keys(queryParams).length) {
                    params.queryParams = queryParams;
                }
                console.log("企业方向列表请求参数：");
                console.log(params);
                axios.post(app_url + "/industry/findPage.do", params).then((response) => {
                    if (response.data.flag) {
                        //this.$message.success(response.data.message);
                        let result = response.data.result;
                        t.pagination.total = result.total;
                        t.items = result.rows;
                        t.loading = true;
                    } else {
                        this.$message.error(response.data.message);
                    }
                })

            },
            //Enter键查询
            handleFilter() {
                this.getList()
            },
            //清除
            handleRest() {
                this.requestParameters = {
                    name: '',
                    isDis: ''
                }
            },
            //搜索
            handleSearch() {
                this.getList();
            },
            handleSizeChange(val) {
                this.pagination.pageSize = val;
                this.pagination.pageNum = 1;
                this.getList();
            },
            handleCurrentChange(val) {
                this.pagination.pageNum = val;
                this.getList();
            },
            // 新增方向
            handleCreate() {
                if (this.$refs['form']) {
                    this.$refs['form'].resetFields();
                }
                this.dialogFormVisible = true;
            },
            //新增方向确定
            handleCreateConfirm() {
                this.dialogFormVisible = false;
                var t = this;
                this.$refs['form'].validate((valid) => {
                    if (valid) {
                        axios.post(app_url + "/industry/add.do", this.form).then((response) => {
                                            if (response.data.flag) {
                                                console.log(response.data);
                                                this.$message.success(response.data.message);
                                                this.getList();
                                            }else {
                                                //失败消息提醒
                                                this.$message.error(response.data.message);
                                            }
                                        }).catch((error)=>{
                                            console.log(error);
                                            this.$message.error("网络异常");
                                        });
                    }
                });
            },
            //新增方向取消
            handleCreateCancel() {
                this.dialogFormVisible = false;
            },
            // 禁用
            handleDisable(row) {
                console.log(row);
                var t = this;
            },
            // 删除
            handleDeleted(row) {
                this.$confirm('此操作将永久删除方向 ' + ', 是否继续?', '提示', {
                    type: 'warning'
                }).then(() => {
                    axios.post(app_url + "/industry/delete.do?id=" + row.id).then((response) => {
                        if (response.data.flag) {
                            console.log(response.data);
                            this.$message.success(response.data.message);
                            this.getList(this.pagination.pageNum);
                        } else {
                            //失败消息提醒
                            this.$message.error(response.data.message);
                        }
                    }).catch((error) => {
                        console.log(error);
                        this.$message.error("网络异常");
                    });
                }).catch(() => {
                    this.$message.info('已取消操作!')
                });
            }
        }
    })
</script>
</html>
